package Thread;

import java.util.concurrent.Semaphore;

public class Demo42 {
    public static void main(String[] args) throws InterruptedException {
        //定义四个可用资源
        Semaphore semaphore = new Semaphore(4);
        //通过acquire关键字申情资源
        semaphore.acquire();
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");
        semaphore.acquire();
        System.out.println("P 操作");

        //释放资源 release
        semaphore.release();
    }
}
